package com.yyh.BookLendSystem.ui;

import org.eclipse.swt.widgets.Composite;

import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.wb.swt.SWTResourceManager;

import com.yyh.BookLendSystem.biz.BizException;
import com.yyh.BookLendSystem.biz.LeadBiz;
import com.yyh.BookLendSystem.biz.ReaderBiz;
import com.yyh.BookLendSystem.util.Utils;

import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;

public class BookCmp extends Composite {
	private LeadBiz biz = new LeadBiz();
	private Object bid;
	private Object rid;
	private Label label;
	private Label label_1;
	private String name;
	//Label label_1
	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public BookCmp(Composite parent, int style) {
		super(parent, style);
		setLayout(null);
		
		label = new Label(this, SWT.NONE);
		
		label.setImage(SWTResourceManager.getImage("D:\\eclipse\\Project\\YC123\\yc123Project\\src\\com\\yyh\\BookLendSystem\\image\\shuihu.jpg"));
		label.setBounds(10, 10, 116, 144);
		
		label_1 = new Label(this, SWT.NONE);
		label_1.setBounds(20, 160, 61, 17);
		label_1.setText("西游记");
		
		
		//鼠标松开之后的事件
		label.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				if(Utils.confirm(getShell(), "是否借阅"+name+"")==false) {
					return;
				}
				try {	
						rid=ReaderBiz.getLoginedUser().get("ID");
						if(biz.lead(rid, bid,name)) {
							Utils.showMessage(getShell(), "借阅成功!");
						}else {
							Utils.showMessage(getShell(), "数量不足,借阅失败!");
						}
												
							
				} catch (BizException  e1) {		
					e1.printStackTrace();
					Utils.showMessage(getShell(), e1.getMessage());
				}
			}
		});

	}
	public BookCmp(Composite parent, int style,String image,String name,Object bid) {
		this(parent,style);
		label.setImage(SWTResourceManager.getImage(image));
		label_1.setText(name);
		this.bid=bid;
		this.name=name;
	}
	
	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}
